﻿/********************************************************
 * 类名：InitPurManageHandler.cs
 * 功能：
 *   ver	变更日		作者			变更内容
 * ────────────────────────────────────────
 *   V01.0	2013-12-23	李波			初版
 *
 * Copyright (c) 2013，李波版权所有
 ********************************************************/
using System;
using System.Web;
using PSS.BLL.InitPurManage;
using PSS.Entity.InitPurManage;
using PSS.Utility;

namespace PSS.WebSite.Service
{
    /// <summary>
    /// InitPurManageHandler 的摘要说明
    /// </summary>
    public class InitPurManageHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var action = StrRequest.GetQueryString("action");
                if (string.IsNullOrEmpty(action)) return;
                var method = this.GetType().GetMethod(action);
                if (method == null) return;
                object[] parameters = { context };
                method.Invoke(this, parameters);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }

        #region 购货单
        public void GetInitPurList(HttpContext context)
        {
            try
            {
                var bll = new InitPurBLL();
                var qcmodel = new InitPurQcEntity
                {
                    DocNumber = context.Request["DocNumber"],
                    VendorId = context.Request["VendorId"],
                    DocDateFrom = context.Request["DocDateFrom"],
                    DocDateEnd = context.Request["DocDateEnd"],
                    PageIndex = Convert.ToInt32(context.Request["pageIndex"]),
                    PageSize = Convert.ToInt32(context.Request["pageSize"]),
                    SortField = context.Request["sortField"],
                    SortOrder = context.Request["sortOrder"]
                };
                var json = bll.GetInitPurList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void AddInitPur(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitPurBLL().AddInitPur(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void ModifyInitPur(HttpContext context)
        {
            try
            {
                var data = context.Request["data"];
                new InitPurBLL().ModifyInitPur(data);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitPurDetailList(HttpContext context)
        {
            try
            {
                var bll = new InitPurDetailBLL();
                var qcmodel = new InitPurDetailQcEntity
                {
                    InitPurId = context.Request["InitPurId"]
                };
                var json = bll.GetInitPurDetailList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetInitPurInfo(HttpContext context)
        {
            try
            {
                var id = context.Request["InitPurId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitPurBLL().GetInitPurInfo(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void RemoveInitPur(HttpContext context)
        {
            try
            {
                var id = context.Request["InitPurId"];
                if (string.IsNullOrEmpty(id)) return;
                var json = new InitPurBLL().RemoveInitPur(id);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void GetTotalInitialNumber(HttpContext context)
        {
            try
            {
                var goodsId = context.Request["GoodsId"];
                var storageId = context.Request["StorageId"];
                if (string.IsNullOrEmpty(goodsId) && string.IsNullOrEmpty(storageId)) return;
                var json = new InitPurBLL().GetTotalInitialNumber(goodsId, storageId);
                context.Response.Write(json);
                //context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        #endregion


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}